﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Kangaroo.Model.Tests
{
    public class PrpsGraphDataGen
    {
        private static readonly Random _random = new Random();

        public static byte[] Generate(Random random = null)
        {
            random = random ?? _random;

            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);
            var graphType = random.NextDouble() > 0.5 ? PrpsGraph.PrpsHeader.GraphType.Prpd : PrpsGraph.PrpsHeader.GraphType.Prps;
            var xSize = (UInt16)random.Next(10);
            var ySize = (UInt16)random.Next(10);

            writer.Write((UInt32)graphType);
            writer.Write(xSize);
            writer.Write(ySize);

            const int headerSize = 32;
            memory.SetLength(headerSize);
            memory.Seek(0, SeekOrigin.End);

            var graphData = Enumerable.Repeat(0, xSize*ySize).Select(p => (float)((random.NextDouble() - 0.5)*3)).ToArray();

            foreach(var data in graphData)
            {
                writer.Write(data);
            }

            writer.Flush();

            var rawData = memory.ToArray();
            return rawData;
        }
    }
}
